home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / obero / Interfaces3_4.lha / Interfaces / Commodities.mod < prev    next >
Text File  |  1994-03-05  |  11KB  |  309 lines

  1. (*
  2. (*
  3. **  Amiga Oberon Interface Module:
  4. **  $VER: Commodities.mod 40.15 (3.1.94) Oberon 3.1
  5. **
  6. **   © 1993 by Fridtjof Siebert
  7. **   updated for V39, V40 by hartmut Goebel
  8. *)
  9. *)
  10.  
  11. MODULE Commodities;
  12.  
  13. IMPORT
  14.   e  * := Exec,
  15.   ie * := InputEvent,
  16.   km * := KeyMap,
  17.   sys  := SYSTEM;
  18.  
  19. (*****************************************************************************)
  20. CONST
  21.   commoditiesName * = "commodities.library";
  22.  
  23. (* Sizes for various buffers *)
  24.   nameLen   * = 24;
  25.   titleLen  * = 40;
  26.   descrLen  * = 40;
  27.  
  28. TYPE
  29.   NameStr * = ARRAY nameLen OF CHAR;
  30.   TitleStr * = ARRAY titleLen OF CHAR;
  31.   DescrStr * = ARRAY descrLen OF CHAR;
  32.  
  33.   NewBrokerPtr * = UNTRACED POINTER TO NewBroker;
  34.   NewBroker * = STRUCT;
  35.     version * : SHORTINT;                  (* must be set to NB_VERSION *)
  36.     name  * : UNTRACED POINTER TO NameStr;
  37.     title * : UNTRACED POINTER TO TitleStr;
  38.     descr * : UNTRACED POINTER TO DescrStr;
  39.     unique * : SET;
  40.     flags  * : SET;
  41.     pri    * : SHORTINT;
  42.     (* new in V5   *)
  43.     port * : e.MsgPortPtr;
  44.     reservedChannel * : INTEGER;
  45.   END;
  46.  
  47. CONST
  48.  
  49. (* constant for NewBroker.version *)
  50.   nbVersion * = 5;        (* Version of NewBroker structure   *)
  51.  
  52. (* Flags for NewBroker.unique *)
  53.   duplicate  * = {};
  54.   unique     * = 0;        (* will not allow duplicates           *)
  55.   notify     * = 1;        (* sends CXM_UNIQUE to existing broker *)
  56.  
  57. (* Flags for NewBroker.flags *)
  58.   showHide * = 2;
  59.  
  60. (*****************************************************************************)
  61. TYPE
  62.  
  63. (* Fake data types for system private objects  *)
  64.   CxObj * = STRUCT END;
  65.   CxMsg * = STRUCT END;
  66.   CxObjPtr * = UNTRACED POINTER TO CxObj;
  67.   CxMsgPtr * = UNTRACED POINTER TO CxMsg;
  68.  
  69. (* Pointer to a function returning a LONG *)
  70.   PFL * = PROCEDURE(): LONGINT;
  71.  
  72. (*****************************************************************************)
  73. CONST
  74.  
  75. (* Commodities Object Types *)
  76.   invalid     * = 0;  (* not a valid object (probably null)  *)
  77.   filter      * = 1;  (* input event messages only           *)
  78.   typeFilter  * = 2;  (* obsolete, do not use                *)
  79.   send        * = 3;  (* sends a message                     *)
  80.   signal      * = 4;  (* sends a signal                      *)
  81.   translate   * = 5;  (* translates input event into chain   *)
  82.   broker      * = 6;  (* application representative          *)
  83.   debug       * = 7;  (* dumps info to serial port           *)
  84.   custom      * = 8;  (* application provides function       *)
  85.   zero        * = 9;  (* system terminator node              *)
  86.  
  87.  
  88. (*****************************************************************************)
  89.  
  90.  
  91. (* Commodities message types *)
  92.   cxmIEvent   * = 5;
  93.   cxmCommand  * = 6;
  94.  
  95. (* Only CXM_IEVENT messages are passed through the input network. Other types
  96.  * of messages are sent to an optional port in your broker. This means that
  97.  * you must test the message type in your message handling, if input messages
  98.  * and command messages come to the same port.
  99.  *
  100.  * CXM_IEVENT: Messages of this type rattle around the Commodities input
  101.  *             network. They are sent to you by a Sender object, and passed
  102.  *             to you as a synchronous function call by a Custom object.
  103.  *
  104.  *             The message port or function entry point is stored in the
  105.  *             object, and the ID field of the message will be set to what
  106.  *             you arrange issuing object.
  107.  *
  108.  *             The data section of the message will point to the input event
  109.  *             triggering the message.
  110.  *
  111.  * CXM_COMMAND: These messages are sent to a port attached to your Broker.
  112.  *              They are sent to you when the controller program wants your
  113.  *              program to do something. The ID value identifies the command.
  114.  *)
  115.  
  116. (* ID values associated with a message of type CXM_COMMAND *)
  117.   cmdDisable   * = 15;  (* please disable yourself       *)
  118.   cmdEnable    * = 17;  (* please enable yourself        *)
  119.   cmdAppear    * = 19;  (* open your window, if you can  *)
  120.   cmdDisappear * = 21;  (* go dormant                    *)
  121.   cmdKill      * = 23;  (* go away for good              *)
  122.   cmdListChg   * = 27;  (* Someone changed the broker list *)
  123.   cmdUnique    * = 25;  (* someone tried to create a broker
  124.                          * with your name. Suggest you appear.
  125.                          *)
  126.  
  127. (*****************************************************************************)
  128. TYPE
  129.  
  130.   InputXpressionPtr * = UNTRACED POINTER TO InputXpression;
  131.   InputXpression * = STRUCT
  132.     version * : SHORTINT;     (* must be set to IX_VERSION  *)
  133.     class   * : SHORTINT;     (* class must match exactly   *)
  134.  
  135.     code     * : SET;         (* Bits that we want          *)
  136.     codeMask * : INTEGER;     (* Set bits here to indicate  *)
  137.                               (* which bits in ix_Code are  *)
  138.                               (* don't care bits.           *)
  139.     qualifier * : SET;        (* Bits that we want          *)
  140.     qualMask  * : SET;        (* Set bits here to indicate  *)
  141.                               (* which bits in ix_Qualifier *)
  142.                               (* are don't care bits        *)
  143.     qualSame * : SET;         (* synonyms in qualifier      *)
  144.   END;
  145.  
  146.   IX * = InputXpression;
  147.   IXPtr * = UNTRACED POINTER TO IX;
  148.  
  149. CONST
  150. (* constant for InputXpression.ix_Version *)
  151.   ixVersion * = 2;
  152.  
  153. (* constants for InputXpression.ix_QualSame *)
  154.   ixSymShift   * = 0;     (* left- and right- shift are equivalent     *)
  155.   ixSymCaps    * = 1;     (* either shift or caps lock are equivalent  *)
  156.   ixSymAlt     * = 2;     (* left- and right- alt are equivalent       *)
  157.  
  158.   ixSymShiftMask * = {ie.lShift,ie.rShift};
  159.   ixSymCapsMask  * = ixSymShiftMask + {ie.capsLock};
  160.   ixSymAltMask   * = {ie.lAlt,ie.rAlt};
  161.  
  162. (* constant for InputXpression.ix_QualMask *)
  163.   ixNormalQuals * = -{ie.relativeMouse}; (* avoid RELATIVEMOUSE *)
  164.  
  165. (*****************************************************************************)
  166.  
  167.  
  168. (* Error returns from CxBroker() *)
  169.   errOk       * = 0;  (* No error                             *)
  170.   errSysErr   * = 1;  (* System error, no memory, etc         *)
  171.   errDup      * = 2;  (* uniqueness violation                 *)
  172.   errVersion  * = 3;  (* didn't understand NewBroker.version  *)
  173.  
  174.  
  175. (*****************************************************************************)
  176.  
  177.  
  178. (* Return values from CxObjError() *)
  179.   coErrIsNull      * = 0;  (* you called CxError(NULL)            *)
  180.   coErrNullAttach  * = 1;  (* someone attached NULL to my list    *)
  181.   coErrBadFilter   * = 2;  (* a bad filter description was given  *)
  182.   coErrBadType     * = 3;  (* unmatched type-specific operation   *)
  183.  
  184. TYPE
  185.   LONGBOOL * = e.LONGBOOL;
  186.  
  187. CONST
  188.   LTRUE * = e.LTRUE;
  189.   LFALSE * = e.LFALSE;
  190.  
  191.  
  192. VAR
  193.   base * : e.LibraryPtr;
  194.  
  195. (*--- functions in V36 or higher (Release 2.0) ---*)
  196. (*
  197.  *  OBJECT UTILITIES
  198.  *)
  199. PROCEDURE CreateCxObj    *{base,- 30}(type{0}      : LONGINT;
  200.                                       arg1{8}      : e.APTR;
  201.                                       arg2{9}      : e.APTR): CxObjPtr;
  202. PROCEDURE CxBroker       *{base,- 36}(VAR nb{8}    : NewBroker;
  203.                                       VAR error{0} : LONGINT): CxObjPtr;
  204. PROCEDURE ActivateCxObj  *{base,- 42}(co{8}        : CxObjPtr;
  205.                                       true{0}      : LONGBOOL): LONGBOOL;
  206. PROCEDURE DeleteCxObj    *{base,- 48}(co{8}        : CxObjPtr);
  207. PROCEDURE DeleteCxObjAll *{base,- 54}(co{8}        : CxObjPtr);
  208. PROCEDURE CxObjType      *{base,- 60}(co{8}        : CxObjPtr): LONGINT;
  209. PROCEDURE CxObjError     *{base,- 66}(co{8}        : CxObjPtr): LONGSET;
  210. PROCEDURE ClearCxObjError*{base,- 72}(co{8}        : CxObjPtr);
  211. PROCEDURE SetCxObjPri    *{base,- 78}(co{8}        : CxObjPtr;
  212.                                       pri{0}       : LONGINT): LONGINT;
  213. (*
  214.  *  OBJECT ATTACHMENT
  215. *)
  216. PROCEDURE AttachCxObj    *{base,- 84}(headobj{8}   : CxObjPtr;
  217.                                       co{9}        : CxObjPtr);
  218. PROCEDURE EnqueueCxObj   *{base,- 90}(headobj{8}   : CxObjPtr;
  219.                                       co{9}        : CxObjPtr);
  220. PROCEDURE InsertCxObj    *{base,- 96}(headobj{8}   : CxObjPtr;
  221.                                       co{9}        : CxObjPtr;
  222.                                       pred{10}     : CxObjPtr);
  223. PROCEDURE RemoveCxObj    *{base,-102}(co{8}        : CxObjPtr);
  224. (*
  225.  *  TYPE SPECIFIC
  226.  *)
  227. PROCEDURE SetTranslate   *{base,-114}(translator{8}: CxObjPtr;
  228.                                       VAR ie{9}    : ie.InputEvent);
  229. PROCEDURE SetFilter      *{base,-120}(filter{8}    : CxObjPtr;
  230.                                       text{9}      : ARRAY OF CHAR);
  231. PROCEDURE SetFilterIX    *{base,-126}(filter{8}    : CxObjPtr;
  232.                                       VAR ix{9}    : IX);
  233. PROCEDURE ParseIX        *{base,-132}(description{8}: ARRAY OF CHAR;
  234.                                       VAR ix{9}    : IX): LONGINT;
  235. (*
  236.  *  COMMON MESSAGE
  237.  *)
  238. PROCEDURE CxMsgType      *{base,-138}(cxm{8}       : CxMsgPtr): LONGSET;
  239. PROCEDURE CxMsgData      *{base,-144}(cxm{8}       : CxMsgPtr): e.APTR;
  240. PROCEDURE CxMsgID        *{base,-150}(cxm{8}       : CxMsgPtr): LONGINT;
  241. (*
  242.  *  MESSAGE ROUTING
  243.  *)
  244. PROCEDURE DivertCxMsg    *{base,-156}(cxm{8}       : CxMsgPtr;
  245.                                       headObj{9}   : CxObjPtr;
  246.                                       returnObj{10}: CxObjPtr);
  247. PROCEDURE RouteCxMsg     *{base,-162}(cxm{8}       : CxMsgPtr;
  248.                                       co{9}        : CxObjPtr);
  249. PROCEDURE DisposeCxMsg   *{base,-168}(cxm{8}       : CxMsgPtr);
  250. (*
  251.  *  INPUT EVENT HANDLING
  252.  *)
  253. PROCEDURE InvertKeyMap   *{base,-174}(ansiCode{0}  : LONGINT;
  254.                                       ie{8}        : ie.InputEventDummyPtr;
  255.                                       km{9}        : km.KeyMapPtr): BOOLEAN;
  256. PROCEDURE AddIEvents     *{base,-180}(ie{8}        : ie.InputEventDummyPtr);
  257.  
  258. (*--- functions in V38 or higher (Release 2.1) ---*)
  259. (*
  260.  * MORE INPUT EVENT HANDLING
  261.  *)
  262. PROCEDURE MatchIX        *{base,-204}(event{8}     : ie.InputEventDummyPtr;
  263.                                       ix{9}        : IXPtr): BOOLEAN;
  264.  
  265. (* $OvflChk- $RangeChk- $StackChk- $NilChk- $ReturnChk- $CaseChk- *)
  266.  
  267. (*************************
  268.  * object creation macros
  269.  *************************)
  270.  
  271. PROCEDURE CxFilter * (d{8}: e.APTR): CxObjPtr;
  272. BEGIN RETURN CreateCxObj(filter, d, NIL); END CxFilter;
  273.  
  274. (*  obsolete since V38, so do not use
  275. PROCEDURE CxTypeFilter * (type{8}: e.APTR): CxObjPtr;
  276. BEGIN RETURN CreateCxObj(typeFilter,type, NIL); END CxTypeFilter;
  277. *)
  278.  
  279. PROCEDURE CxSender * (port{8}: e.MsgPortPtr; id{9}: e.APTR): CxObjPtr;
  280. BEGIN RETURN CreateCxObj(send,port,id); END CxSender;
  281.  
  282. PROCEDURE CxSignal * (task{8}: e.TaskPtr; sig{9}: INTEGER): CxObjPtr;
  283. BEGIN RETURN CreateCxObj(signal,task,sig); END CxSignal;
  284.  
  285. PROCEDURE CxTranslate * (ie{8}: ie.InputEventDummyPtr): CxObjPtr;
  286. BEGIN RETURN CreateCxObj(translate,ie,NIL); END CxTranslate;
  287.  
  288. PROCEDURE CxDebug * (id{8}: e.APTR): CxObjPtr;
  289. BEGIN RETURN CreateCxObj(debug,id, NIL); END CxDebug;
  290.  
  291. TYPE
  292.   CustomProcType * = PROCEDURE(obj: CxObjPtr; msg: CxMsgPtr);
  293.  
  294. PROCEDURE CxCustom * (action{8}: CustomProcType; id{9}: e.APTR): CxObjPtr;
  295. BEGIN RETURN CreateCxObj(custom,sys.VAL(e.APTR,action),id); END CxCustom;
  296.  
  297. (* matches nothing   *)
  298. PROCEDURE NullIx * (VAR i{8}: IX): BOOLEAN;
  299. BEGIN RETURN i.class = ie.null; END NullIx;
  300.  
  301.  
  302. BEGIN
  303.   base :=  e.OpenLibrary(commoditiesName,37);
  304.  
  305. CLOSE
  306.   IF base#NIL THEN e.CloseLibrary(base) END;
  307.  
  308. END Commodities.
  309.